/* ---------------------------------------------------------------------- */
/* Script generated with: DeZign for Databases vV7.0.1                    */
/* Target DBMS:           MS SQL Server 2005                              */
/* Project file:          phatphucloc.dez                                 */
/* Project name:                                                          */
/* Author:                                                                */
/* Script type:           Database creation script                        */
/* Created on:            2012-04-29 01:05                                */
/* ---------------------------------------------------------------------- */


/* ---------------------------------------------------------------------- */
/* Tables                                                                 */
/* ---------------------------------------------------------------------- */

/* ---------------------------------------------------------------------- */
/* Add table "sys_Function"                                               */
/* ---------------------------------------------------------------------- */

CREATE TABLE [sys_Function] (
    [ID] INTEGER IDENTITY(0,1) NOT NULL,
    [Name] NVARCHAR(100),
    [Image] NVARCHAR(100),
    [Link] NVARCHAR(100),
    [ParentID] NVARCHAR(40),
    [Last_update] VARCHAR(17),
    [User1] NVARCHAR(40),
    [User2] NVARCHAR(40),
    [User3] NVARCHAR(40),
    [User4] NVARCHAR(40),
    [User5] NVARCHAR(40),
    CONSTRAINT [PK_sys_Function] PRIMARY KEY ([ID])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "VaiTro"                                                     */
/* ---------------------------------------------------------------------- */

CREATE TABLE [VaiTro] (
    [ID] INTEGER IDENTITY(0,1) NOT NULL,
    [Ten] NVARCHAR(50),
    [Ghi_chu] NVARCHAR(100),
    [Ngay_cap_nhat_cuoi] VARCHAR(17),
    [User1] NVARCHAR(40),
    [User2] NVARCHAR(40),
    [User3] NVARCHAR(40),
    [User4] NVARCHAR(40),
    [User5] NVARCHAR(40),
    CONSTRAINT [PK_VaiTro] PRIMARY KEY ([ID])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "ThanhVien"                                                  */
/* ---------------------------------------------------------------------- */

CREATE TABLE [ThanhVien] (
    [ID] INTEGER IDENTITY(0,1) NOT NULL,
    [Ten_dang_nhap] NVARCHAR(50),
    [Mat_khau] NVARCHAR(100),
    [Ma_vai_tro] INTEGER,
    [Ngay_cap_nhat_cuoi] VARCHAR(17),
    [User1] NVARCHAR(40),
    [User2] NVARCHAR(40),
    [User3] NVARCHAR(40),
    [User4] NVARCHAR(40),
    [User5] NVARCHAR(40),
    CONSTRAINT [PK_ThanhVien] PRIMARY KEY ([ID])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "KhachHang"                                                  */
/* ---------------------------------------------------------------------- */

CREATE TABLE [KhachHang] (
    [ID] INTEGER IDENTITY(0,1) NOT NULL,
    [Ten] NVARCHAR(50),
    [Dia_chi] NVARCHAR(500),
    [Tel] VARCHAR(40),
    [Fax] VARCHAR(40),
    [Email] NVARCHAR(50),
    [So_tai_khoan] VARCHAR(40),
    [Ngan_hang] NVARCHAR(40),
    [Ma_so_thue] VARCHAR(40),
    [Ghi_chu] NVARCHAR(100),
    [Ngay_cap_nhat_cuoi] VARCHAR(17),
    [User1] NVARCHAR(40),
    [User2] NVARCHAR(40),
    [User3] NVARCHAR(40),
    [User4] NVARCHAR(40),
    [User5] NVARCHAR(40),
    CONSTRAINT [PK_KhachHang] PRIMARY KEY ([ID])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "NhomHang"                                                   */
/* ---------------------------------------------------------------------- */

CREATE TABLE [NhomHang] (
    [ID] INTEGER IDENTITY(0,1) NOT NULL,
    [Ten] NVARCHAR(50),
    [Ghi_chu] NVARCHAR(100),
    [Ngay_cap_nhat_cuoi] VARCHAR(17),
    [User1] NVARCHAR(40),
    [User2] NVARCHAR(40),
    [User3] NVARCHAR(40),
    [User4] NVARCHAR(40),
    [User5] NVARCHAR(40),
    CONSTRAINT [PK_NhomHang] PRIMARY KEY ([ID])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "sys_Role_Function"                                          */
/* ---------------------------------------------------------------------- */

CREATE TABLE [sys_Role_Function] (
    [ID] INTEGER IDENTITY(0,1) NOT NULL,
    [RoleID] INTEGER NOT NULL,
    [FuctionID] INTEGER NOT NULL,
    [Last_update] VARCHAR(17),
    [User1] NVARCHAR(40),
    [User2] NVARCHAR(40),
    [User3] NVARCHAR(40),
    [User4] NVARCHAR(40),
    [User5] NVARCHAR(40),
    CONSTRAINT [PK_sys_Role_Function] PRIMARY KEY ([ID])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "HangHoa"                                                    */
/* ---------------------------------------------------------------------- */

CREATE TABLE [HangHoa] (
    [ID] INTEGER IDENTITY(0,1) NOT NULL,
    [Ten] NVARCHAR(50),
    [Ma_hang] VARCHAR(50),
    [Ma_nhom_hang] INTEGER,
    [Ghi_chu] NVARCHAR(2000),
    [Gia_nhap] FLOAT,
    [Ngay_cap_nhat_cuoi] VARCHAR(17),
    [User1] NVARCHAR(40),
    [User2] NVARCHAR(40),
    [User3] NVARCHAR(40),
    [User4] NVARCHAR(40),
    [User5] NVARCHAR(40),
    CONSTRAINT [PK_HangHoa] PRIMARY KEY ([ID])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "KhachHang_HangHoa"                                          */
/* ---------------------------------------------------------------------- */

CREATE TABLE [KhachHang_HangHoa] (
    [ID] INTEGER IDENTITY(0,1) NOT NULL,
    [Ma_Hang_Hoa] INTEGER,
    [Ma_Khach_Hang] INTEGER,
    [Gia_Ban] FLOAT,
    [User1] NVARCHAR(40),
    [User2] NVARCHAR(40),
    [User3] NVARCHAR(40),
    [User4] NVARCHAR(40),
    [User5] NVARCHAR(40),
    CONSTRAINT [PK_KhachHang_HangHoa] PRIMARY KEY ([ID])
)
GO


/* ---------------------------------------------------------------------- */
/* Foreign key constraints                                                */
/* ---------------------------------------------------------------------- */

ALTER TABLE [sys_Role_Function] ADD CONSTRAINT [sys_Function_sys_Role_Function] 
    FOREIGN KEY ([FuctionID]) REFERENCES [sys_Function] ([ID])
GO


ALTER TABLE [sys_Role_Function] ADD CONSTRAINT [VaiTro_sys_Role_Function] 
    FOREIGN KEY ([RoleID]) REFERENCES [VaiTro] ([ID])
GO


ALTER TABLE [ThanhVien] ADD CONSTRAINT [VaiTro_ThanhVien] 
    FOREIGN KEY ([Ma_vai_tro]) REFERENCES [VaiTro] ([ID])
GO


ALTER TABLE [HangHoa] ADD CONSTRAINT [NhomHang_HangHoa] 
    FOREIGN KEY ([Ma_nhom_hang]) REFERENCES [NhomHang] ([ID])
GO


ALTER TABLE [KhachHang_HangHoa] ADD CONSTRAINT [KhachHang_KhachHang_HangHoa] 
    FOREIGN KEY ([Ma_Khach_Hang]) REFERENCES [KhachHang] ([ID])
GO


ALTER TABLE [KhachHang_HangHoa] ADD CONSTRAINT [HangHoa_KhachHang_HangHoa] 
    FOREIGN KEY ([Ma_Hang_Hoa]) REFERENCES [HangHoa] ([ID])
GO

